package thread;

/**
 * Created with IntelliJ IDEA.
 * Description:中断线程方法1-使用标志位
 * User: bjc
 * Date: 2025-08-15
 * Time: 19:27
 */
public class ThreadDemo10 {
    private static boolean isQuit = false;

    public static void main(String[] args) {
        Thread t = new Thread(() -> {
            while (!isQuit) {
                System.out.println("我是一个线程，正在工作中...");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            System.out.println("线程执行完毕！");
        }
        );
        t.start();
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        isQuit = true;
        System.out.println("让t线程结束");
//        isQuit = true;
    }
}
